<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML" 4.01"//EN" "http://www.w3.org/TR/html4/strict.dtd">
<!-- Created: August 13, 2001-->
<!--
$Id: MachineAdd2.php,v 1.3 2001/11/02 19:05:26 eugenem Exp eugenem $
$Header: /export/home/eugenem/public_html/ComplianceReports/RCS/MachineAdd2.php,v 1.3 2001/11/02 19:05:26 eugenem Exp eugenem $
$Log: MachineAdd2.php,v $
Revision 1.3  2001/11/02 19:05:26  eugenem
Moved HTTP_*_VARS processing to dbc.inc

Revision 1.2  2001/11/02 14:57:27  eugenem
Moved database connect statements to a separate file.

Revision 1.1  2001/11/02 14:57:02  eugenem
Initial revision

Revision 1.2  2001/08/15 15:26:24  eugenem
*** empty log message ***

-->

<html>
<head>
<title>Radiological Equipment Database</title>
<meta name="author" content="Eugene Mah">
<link rev="made" href="mailto:eugenem@ix.netcom.com">
<link rev="home" href="http://home.netcom.com/~eugenem/">
<meta name="description" content="">
<meta name="Keywords" content="">
<meta name="Reply-to" content="eugenem@ix.netcom.com">
<META http-equiv="PICS-Label" content='(PICS-1.1 "http://www.classify.org/safesurf/" l r (SS~~0001))'>
<?PHP
require('functions.inc');
require('dbc.inc');

?>
</head>

<body>
<h1>Radiological Equipment Database</h1>
<?PHP
$modality = mysql_query("select * from Modality");
$manuf = mysql_query("select * from Manufacturer");
$loc = mysql_query("select * from Location");
$contact = mysql_query("select ContactPID,Name from ContactPeople");

if (isset($ModalityID) && isset($Description)) {
  /*
    First check the database to see if we already have a machine
    with a matching manufacturer, model, and serial number
  */
  $query = "SELECT ManufacturerID,Model,SerialNumber 
            FROM Machines 
      WHERE ManufacturerID=$ManufacturerID 
      AND Model=\"$Model\" AND SerialNumber=\"$SerialNumber\"";

  $result = mysql_query($query)
    or die ("Query failed: $query<br>");

  if ($row = mysql_fetch_row($result)) { // This machine already exists
    echo "<h2>Machine not entered</h2>";
    echo "A machine with $Model, SN $SN already exists in the database<br>";
  }
  else { // Go ahead and insert into the database
    if (empty($InstallDate) || $InstallDate=="" || !isset($InstallDate)) $InstallDate = date("Y-m-d");
  if (empty($VendSiteID) || !isset($VendSiteID)) $VendSiteID = "";
  
    $query = "INSERT INTO Machines 
            (ModalityID,Description,ManufacturerID,VendSiteID,Model,SerialNumber,ManufDate,InstallDate,LocationID,Room,Status,Notes)
        VALUES
          ($ModalityID,\"$Description\",$ManufacturerID,\"$VendSiteID\",\"$Model\",\"$SerialNumber\",\"$ManufDate\",\"$InstallDate\",$LocationID,\"$Room\",\"$Status\",\"$Notes\")";
    $result = mysql_query($query)
      or die ("Insert failed: $query<br>");

    // Get the record number of the machine that was just inserted
    $MachID = mysql_insert_id();

    // Check to see if any contacts submitted.
    if (!isset($Contact1PID)) $Contact1PID = 0;
    if (!isset($Contact2PID)) $Contact2PID = 0;
    
    // Add contact info to Contacts table
    $query = "INSERT INTO Contacts2Machine (MachineID,ContactPID) VALUES ($MachID,$Contact1PID)";
    $result = mysql_query($query)
      or die ("Insert failed: $query<br>");
    $query = "INSERT INTO Contacts2Machine (MachineID,ContactPID) VALUES ($MachID,$Contact2PID)";
    $result = mysql_query($query)
      or die ("Insert failed: $query<br>");

    echo "<h2>Machine Added</h2>";
    echo "<p>$Description $Model $SerialNumber was added to the database with record number $MachID </p>";
  }
?>

<h2>Add a tube</h2>
<form action="TubeAdd.php" method="POST">
<input type="HIDDEN" name="MachID" value="<?PHP echo $MachID; ?>">
<p>Housing Manufacturer: <?PHP echo listbox_field($manuf, "HsgManufID",""); mysql_data_seek($manuf,0); ?></p>
<p>Housing Model: <input type="TEXT" name="HMod" size="20"></p>
<p>Housing SN: <input type="TEXT" name="HSN" size="20"></p>
<p>Insert Manufacturer: <?PHP echo listbox_field($manuf,"InsertManufID",""); mysql_data_seek($manuf,0); ?></p>
<p>Insert Model: <input type="TEXT" name="IMod" size="20"></p>
<p>Insert SN: <input type="TEXT" name="ISN" size="20"></p>
<p>Manufacture Date: <input type="TEXT" name="ManufDate" size="10"> (YYYY-MM-DD)</p>
<p>Focal spot size: Large: <input type="TEXT" name="LFS" size="4">mm
Medium: <input type="TEXT" name="MFS" size="4">mm Small: <input type="TEXT" name="SFS" size="4">mm</p>
<p><textarea name="Notes" rows="3" cols="70">Additional notes about this tube</textarea></p>
<p><input type="SUBMIT" value="Add Tube"> / <input type="RESET" value="Reset"> / <a href="index.html" target="_top" >Main</a></p>
</form>
<hr>

<?PHP
}
?>
<h2>Add a machine</h2>
<form action="MachineAdd2.php" method="POST">
<p>Modality: <?PHP echo listbox_field($modality, "ModalityID", ""); ?></p>
<p>Description: <input type="TEXT" name="Description" size="25"></p>
<p>Manufacturer: <?PHP echo listbox_field($manuf, "ManufacturerID", ""); ?></p>
<p>Model: <input type="TEXT" name="Model" size="20"></p>
<p>Serial Number: <input type="TEXT" name="SerialNumber" size="20"></p>
<p>Vendor Site ID: <input type="text" name="VendSiteID" size="20" /></p>
<p>Manufacture Date:  <input type="TEXT" name="ManufDate" size="10"> (YYYY-MM-DD)</p>
<p>Install Date: <input type="TEXT" name="InstallDate" size="10"> (YYYY-MM-DD)</p>
<p>Location: <?PHP echo listbox_field($loc, "LocationID", ""); ?></p>
<p>Room: <input type="TEXT" name="Room" size="20"></p>
<p>Machine status
  <select name="Status" size="1">
    <option value="Active" selected="selected">Active</option>
    <option value="Inactive">Inactive</option>
    <option value="Removed">Removed</option>
  </select>
</p>
<p>Notes: <textarea name="Notes" rows="3" cols="70">Enter any notes about the machine here</textarea></p>
<p>Contact Person: <?PHP echo listbox_field($contact, "Contact1PID", "0"); mysql_data_seek($contact,0); ?></p>
<p>Contact Person: <?PHP echo listbox_field($contact, "Contact2PID", "0"); ?></p>
<p><input type="SUBMIT" value="Add machine"> / <input type="RESET" value="Reset"> / <a href="index.html" target="_top" >Main</a></p>
</form>

<?PHP mysql_close(); ?>

</body>
</html>
